//
//  GuanFongActivityViewController.m
//  MyYiJianKangApp
//
//  Created by 张国文 on 16/4/6.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "GuanFongActivityViewController.h"
#import "GuanFangActivityModel.h"
#import "GuanFangTableViewCell.h"
#import "GuanFangActivityDetailViewController.h"
#import "SDCycleScrollView.h"


@interface GuanFongActivityViewController ()<UITableViewDataSource, UITableViewDelegate, SDCycleScrollViewDelegate>

@property (nonatomic, strong) UITableView *guanFangListTableView;
@property (nonatomic, strong) NSMutableArray *guanFangListDataArray; // 官方活动数据源
@property (nonatomic, strong) NSMutableArray *scrollViewImageArray; // 轮播图数组

@end

@implementation GuanFongActivityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor =[UIColor whiteColor];
    // navi的修改
    [self changeNavigation];
    // 数据源
    [self addData];
    // 布局
    [self addMySubview];
}

// navi的修改
- (void)changeNavigation
{
    [self.navigationController.navigationBar setTranslucent:NO];
    self.navigationItem.title = @"官方活动列表";
    UIImageView *leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    leftImageView.image = [UIImage imageNamed:@"houtui"];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftImageView];
    UITapGestureRecognizer *leftTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lastPage:)];
    [leftImageView addGestureRecognizer:leftTapGes];
    
}

#pragma mark - 返回上一页面
- (void)lastPage:(UITapGestureRecognizer *)tapGes
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 数据源
- (void)addData
{
    NSDictionary *dic1 = [NSDictionary dictionaryWithObjectsAndKeys:@"壹基因的第一个活动", @"_title", @[@"我是健康达人", @"运动"], @"_remark", @"2016.3.10-2016.3.15", @"_time", @"20", @"memberCount" ,nil];
    NSDictionary *dic2 = [NSDictionary dictionaryWithObjectsAndKeys:@"壹基因的第二个活动", @"_title", @[@"运动", @"健康达人", @"运动"], @"_remark", @"2016.4.15-2016.4.20", @"_time", @"1000", @"_memberCount" ,nil];
    NSArray *tempArray = [NSArray arrayWithObjects:dic1, dic2, nil];
    // 初始化数组
    self.guanFangListDataArray = [NSMutableArray array];
    
    for (NSDictionary *tempDic in tempArray) {
        GuanFangActivityModel *model = [[GuanFangActivityModel alloc] init];
        [model setValuesForKeysWithDictionary:tempDic];
        [self.guanFangListDataArray addObject:model];
    }
}

#pragma mark - 布局
- (void)addMySubview
{
    self.guanFangListTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) style:UITableViewStylePlain];
    self.guanFangListTableView.dataSource = self;
    self.guanFangListTableView.delegate = self;
    [self.view addSubview:_guanFangListTableView];
    
    // 构建表头
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 150 * kAdjustParamater)];
    headerView.backgroundColor = [UIColor whiteColor];
    self.guanFangListTableView.tableHeaderView = headerView;
    
    // 构建轮播图数组
    UIImage *image1 = [UIImage imageNamed:@"活动类型图切图-01"];
    UIImage *image2 = [UIImage imageNamed:@"活动类型图切图-02"];
    self.scrollViewImageArray = [NSMutableArray arrayWithObjects:image1, image2, nil];
    
    SDCycleScrollView *scrollerIVew = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kScreenWidth, 150 * kAdjustParamater) imageNamesGroup:self.scrollViewImageArray];
    scrollerIVew.pageControlDotSize = CGSizeMake(5 * kAdjustParamater, 5 * kAdjustParamater);
    scrollerIVew.currentPageDotColor = kCyanColor;
    scrollerIVew.pageDotColor = [UIColor whiteColor];
    scrollerIVew.delegate = self;
    [headerView addSubview:scrollerIVew];
    
   
    
}

#pragma mark - 选中图片执行
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    NSLog(@"点击了index = %ld", index);
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.guanFangListDataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"guanFangCell";
    GuanFangTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[GuanFangTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = self.guanFangListDataArray[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 120 * kAdjustParamater;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    GuanFangActivityDetailViewController *detailVC = [[GuanFangActivityDetailViewController alloc] init];
    [self.navigationController pushViewController:detailVC animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
